/*
 * Copyright (C) 2010 by CODEBISTRO LLC.
 *
 * The license is granted to use, reproduce, modify, display, perform, sublicense
 * and distribute this code under the conditions of the Mozilla Public License v 1.1.
 *
 * The text of the license is available with this source as MPL-1.1.txt
 * or at http://www.mozilla.org/MPL/MPL-1.1.txt.
 */

package org.codebistro.util;

import org.apache.wicket.util.crypt.Base64UrlSafe;

import java.security.SecureRandom;
import java.util.Random;

public class RandomUtils {
    static Random random = new SecureRandom(Long.toString(
            System.currentTimeMillis() ^ 0x34d6b6177eda059bL).getBytes());
    
    /**
     * @param byteLength -- length of random number in bytes. The output will be 4/3
     *                   that size.
     * @return random string of Base64 encoded (with URL safety) bytes
     */
    public static String randomBase64URLSafe(int byteLength) {
        byte[] idBytes = new byte[byteLength];
        RandomUtils.random.nextBytes(idBytes);
        return new String(Base64UrlSafe.encodeBase64(idBytes));
    }

}
